﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using System.Data;

namespace JM.JCY.SharePointComponent.Committee.CommitteeMember
{
    public partial class CommitteeMemberUserControl : UserControl
    {
        public int _userId
        {
            set { ViewState["_userId"] = value; }
            get { return (int)ViewState["_userId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ApplicationContext.Current.GetKeyValue("userId") != null)
            {
                _userId = Int32.Parse(ApplicationContext.Current.GetKeyValue("userId").ToString());
            }

            if (!IsPostBack)
            {
                if (Request.QueryString["CommitteeId"] != null)
                {
                    using (UserManagementProxy userProxy = new UserManagementProxy())
                    {
                        this.hfCommitteeId.Value = Request.QueryString["CommitteeId"].ToString();

                        CommitteeDataSet.T_CommitteeDataTable committeeDT = userProxy.GetCommitteeById(Int32.Parse(Request.QueryString["CommitteeId"].ToString()));
                        if (committeeDT.Rows.Count > 0)
                        {
                            this.lblCommitteeName.Text = committeeDT[0].CommitteeName;                          
                        }

                        // load members
                        CommitteeDataSet.T_Committee_MemberDataTable memberDT = userProxy.GetCommitteeMember(Int32.Parse(Request.QueryString["CommitteeId"].ToString()));
                        this.dlUserMember.DataSource = memberDT;
                        this.dlUserMember.DataBind();
                    }

                }
            }

        }

        protected void dlUserMember_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal viewLink = (Literal)e.Item.FindControl("ltImgPic");
                viewLink.Text = "<a href='/PersonalSite/PersonalPages/PublicUser.aspx?StaffId=" + drv["UserId"].ToString() + "'> <img src='" + drv["PhotoImagePath"].ToString() + "' alt='" + drv["UserName"].ToString() + "' width='110px' height='128'></a>";
            }
        }
    }
}
